package com.github.kuzan7.webdemo.vo;


import com.github.kuzan7.webdemo.constants.BaseCodeEnum;
import com.github.kuzan7.webdemo.constants.ErrorDescBase;
import java.io.Serializable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Result implements Serializable {
    private static final Logger log = LoggerFactory.getLogger(Result.class);
    private static final long serialVersionUID = 1L;
    private String code;
    private String message;
    private Object data;

    private static Result result(String code, String detailCode, String message, Object data) {
        Result rtnData = new Result();
        rtnData.setCode(code);
        rtnData.setMessage(message);
        rtnData.setData(data);
        return rtnData;
    }

    public boolean isOk() {
        return BaseCodeEnum.OK.getCode().equals(this.code);
    }

    public static Result ok(String code, String message, Object data) {
        return result(code, "", message, data);
    }

    public static Result ok(Object result) {
        return ok(BaseCodeEnum.OK.getCode(), BaseCodeEnum.OK.getMessage(), result);
    }

    public static Result ok() {
        return ok((Object)null);
    }

    public static Result fail(String code, String detailCode, String message) {
        return result(code, detailCode, message, (Object)null);
    }

    public static Result fail(String code, String detailCode, String message, Object data) {
        return result(code, detailCode, message, data);
    }

    public static Result fail(String code, String message, Object data) {
        return result(code, "", message, data);
    }

    public static Result fail(String code, String message) {
        return fail(code, "", message);
    }

    public static Result fail() {
        return fail(BaseCodeEnum.ERROR.getCode(), BaseCodeEnum.ERROR.getMessage());
    }

    public static Result fail(ErrorDescBase error) {
        return fail(error.getCode(), error.getMessage());
    }

    public Result() {
    }

    public String getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public Object getData() {
        return this.data;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
